"""
配置管理模块

集中管理所有默认配置，避免硬编码问题
"""

import os
from pathlib import Path

# 获取项目根目录
PROJECT_ROOT = Path(__file__).parent.parent

class Config:
    """配置管理类"""
    
    # 数据路径配置
    DEFAULT_UNITS_DATA_FILE = PROJECT_ROOT / "data" / "processed" / "units_prs_open.jsonl"
    DEFAULT_LABEL_DATA_DIR = PROJECT_ROOT / "data" / "label_data"
    DEFAULT_EMBEDDING_DIR = "data/label_embedding"  # 相对于 llm_few_shot 目录
    DEFAULT_OUTPUT_DIR = "data/validation_results"  # 相对于 llm_few_shot 目录
    
    # 模型配置
    DEFAULT_EMBEDDING_MODEL = "sentence-transformers/paraphrase-multilingual-mpnet-base-v2"
    DEFAULT_LLM_MODEL = "Qwen/Qwen3-8B"
    
    # API 配置
    DEFAULT_BASE_URL = "https://api.siliconflow.cn"
    DEFAULT_API_KEY = "EMPTY"
    
    # 日志配置
    DEFAULT_LOG_DIR = "logs"  # 相对于 llm_few_shot 目录
    DEFAULT_FEW_SHOT_LOG_DIR = "logs/few_shot_selections"  # 相对于 llm_few_shot 目录
    
    # 采样配置
    DEFAULT_SAMPLE_COUNT = 10
    DEFAULT_TOP_K = 5
    
    # 评分配置
    DEFAULT_SCORE_THRESHOLD = 0.0
    
    @classmethod
    def get_units_data_file(cls) -> str:
        """获取单元数据文件路径"""
        env_path = os.getenv('UNITS_FILE')
        if env_path:
            return env_path
        return str(cls.DEFAULT_UNITS_DATA_FILE)
    
    @classmethod
    def get_embedding_dir(cls) -> str:
        """获取嵌入目录路径"""
        env_path = os.getenv('EMBEDDING_DIR')
        if env_path:
            return env_path
        return cls.DEFAULT_EMBEDDING_DIR
    
    @classmethod
    def get_output_dir(cls) -> str:
        """获取输出目录路径"""
        env_path = os.getenv('OUT_DIR')
        if env_path:
            return env_path
        return cls.DEFAULT_OUTPUT_DIR
    
    @classmethod
    def get_model_name(cls) -> str:
        """获取模型名称"""
        return os.getenv('MODEL_NAME', cls.DEFAULT_LLM_MODEL)
    
    @classmethod
    def get_embedding_model(cls) -> str:
        """获取嵌入模型名称"""
        return os.getenv('EMBEDDING_MODEL', cls.DEFAULT_EMBEDDING_MODEL)
    
    @classmethod
    def get_api_key(cls) -> str:
        """获取API密钥"""
        return os.getenv('API_KEY', cls.DEFAULT_API_KEY)
    
    @classmethod
    def get_base_url(cls) -> str:
        """获取API基础URL"""
        return os.getenv('BASE_URL', cls.DEFAULT_BASE_URL)
    
    @classmethod
    def get_log_dir(cls) -> str:
        """获取日志目录"""
        return os.getenv('LOG_DIR', cls.DEFAULT_LOG_DIR)
    
    @classmethod
    def get_few_shot_log_dir(cls) -> str:
        """获取few-shot日志目录"""
        return os.getenv('FEW_SHOT_SELECTION_LOG_DIR', cls.DEFAULT_FEW_SHOT_LOG_DIR)
    
    @classmethod
    def get_sample_count(cls) -> int:
        """获取采样数量"""
        try:
            return int(os.getenv('SAMPLE_COUNT', cls.DEFAULT_SAMPLE_COUNT))
        except (ValueError, TypeError):
            return cls.DEFAULT_SAMPLE_COUNT
    
    @classmethod
    def get_top_k(cls) -> int:
        """获取top-k数量"""
        try:
            return int(os.getenv('TOP_K', cls.DEFAULT_TOP_K))
        except (ValueError, TypeError):
            return cls.DEFAULT_TOP_K
